require 'java'

import org.eclipse.jface.dialogs.MessageDialog
import org.eclipse.swt.SWT
import org.eclipse.swt.layout.GridLayout
  
module Widgets
  include_package 'org.eclipse.swt.widgets'
end
    
class MyView < Java::org.eclipse.ui.part.ViewPart
  
	def createPartControl(composite) 
		
		l = GridLayout.new
    l.numColumns = 4
        
		composite.setLayout(l)
		
		text =  Widgets::Text.new(composite,  SWT::SINGLE)
		
		button =  Widgets::Button.new(composite,  SWT::PUSH)
		button.setText("Say it!")
		
		label =  Widgets::Label.new(composite,  SWT::HORIZONTAL)
		label.setText("This is the Demo view!")
	
		button.addListener(  SWT::Selection, MyListener.new(label, text))
		
	end

	def setFocus()
    	
	end
	
    def dispose()
    	
    end
    
  # the "part" class must implement a meaningful equals() method
  # as the PartTester class will verify this 
  def equals(object)
    if object.nil?
      return false
    end
    
    if object.equal?(self)
      return true
    elsif object.kind_of?(Java::org.eclipse.ui.IViewPart)
      return true
    end
    
    return false
  end  
end

class MyListener  
  include org.eclipse.swt.widgets.Listener

  attr_accessor :l
  attr_accessor :t
	
    def initialize(label, text)
        @l = label
        @t = text      
    end
    def handleEvent(event) 
        l.setText(t.getText())
    end
end

$view = MyView.new()
$view

